package com.dingqb.ktdemo.data

class SealedD {

}

sealed class Expr
data class Const(val number: Double) : Expr()
data class Sum(val e1: Expr, val e2: Expr) : Expr()
object NotANumber : Expr()

fun eval(expr: Expr): Double = when (expr) {
    is Const -> expr.number
    is Sum -> eval(expr.e1) + eval(expr.e2)
    NotANumber -> Double.NaN
}

fun main(args: Array<String>) {
    var v = Const(18.8);
    var ev = eval(v);
    println(ev);
    println(execute(UiOp.Show));
    println(UiOp.Show);
}

sealed class UiOp {
    object Show : UiOp();
    object Hide : UiOp();
}

fun execute(op: UiOp) = when (op) {
    UiOp.Show -> "show"
    UiOp.Hide -> "hide"
}

